<template>
  <div class="app-container">
    <el-card>
      <div slot="header">
        <el-input
          style="width:200px"
          class="mr-4"
          v-model="form.nickname"
          clearable
          placeholder="请输入用户昵称"
        ></el-input>
        <!-- <el-input
          style="width:200px"
          class="mr-4"
          v-model="form.mobile"
          clearable
          placeholder="请输入手机号"
        ></el-input> -->
        <el-input
          style="width:200px"
          class="mr-4"
          v-model="form.user_id"
          clearable
          placeholder="请输入用户ID"
        ></el-input>
        <el-button type="primary" @click="getUserData(1, 10)">查询</el-button>
        <el-button type="primary" @click="resetReset">重置</el-button>
      </div>
      <el-table border :data="tableList" style="width: 100%">
        <el-table-column prop="user_id" label="用户ID"></el-table-column>
        <el-table-column prop="nickname" label="用户昵称"></el-table-column>
        <el-table-column prop="head_picture" label="头像">
          <template slot-scope="scope">
            <el-image
              style="width: 100px; height: 100px"
              :src="scope.row.head_picture"
              :preview-src-list="[scope.row.head_picture]"
            >
            </el-image>
            <!--          <span>{{ scope.row.head_picture }}</span>-->
          </template>
        </el-table-column>
        <el-table-column prop="join_num" label="参与次数"></el-table-column>
        <el-table-column prop="cost" label="累计投入"></el-table-column>
        <el-table-column prop="get_num" label="累计获得"></el-table-column>
        <el-table-column prop="total" label="合计"></el-table-column>
      </el-table>
      <div class="page mt-4 flex justify-end">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageList.page"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageList.per_page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageList.total"
          background
        >
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import titleHeader from "../grabCandyConfig/childComps/titleHeader";
import {userDataAPI} from "../../../api/gradCandy/gradCandy";

export default {
  name: "userProfitLossStatement",
  components: {
    titleHeader
  },
  data() {
    return {
      loading: false,
      tableList: [],
      pageList: {
        page: 1,
        total: 200,
        per_page: 10
      },
      form: {
        nickname: null,
        mobile: null,
        user_id: null
      }
    };
  },
  created() {
    this.getUserData();
  },
  methods: {
    async getUserData(page = 1, per_page = 10) {
      this.loading = true;
      let params = {
        page: page,
        per_page: per_page
      };
      params = Object.assign(params, this.form);
      console.log(params);
      const detail = await userDataAPI(params);
      if (detail.code === 200) {
        this.tableList = detail.data.data;
        // 处理页码
        this.pageList.page = detail.data.current_page;
        this.pageList.total = detail.data.total;
        this.loading = false;
      }
    },
    // 重置按钮点击
    resetReset() {
      for (const key in this.form) {
        this.form[key] = null;
      }
      this.getUserData();
    },
    // 分页事件
    handleSizeChange(val) {
      // `每页 ${val} 条`);
      this.pageList.per_page = val;
      this.getUserData(this.pageList.page, this.pageList.per_page);
    },
    handleCurrentChange(val) {
      // `当前页: ${val}`);
      this.pageList.page = val;
      this.getUserData(this.pageList.page, this.pageList.per_page);
    }
  }
};
</script>

<style scoped lang="scss">
@import "index";
</style>
